package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.vo.SysCollectResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysCollectMapper;
import com.ruoyi.system.domain.SysCollect;
import com.ruoyi.system.service.ISysCollectService;

/**
 * 酒店收藏Service业务层处理
 * 
 * @author dht
 * @date 2025-04-28
 */
@Service
public class SysCollectServiceImpl implements ISysCollectService 
{
    @Autowired
    private SysCollectMapper sysCollectMapper;

    /**
     * 查询酒店收藏
     * 
     * @param userId 酒店收藏主键
     * @return 酒店收藏
     */
    @Override
    public SysCollect selectSysCollectByUserId(Long userId)
    {
        return sysCollectMapper.selectSysCollectByUserId(userId);
    }

    /**
     * 查询酒店收藏列表
     * 
     * @param sysCollect 酒店收藏
     * @return 酒店收藏
     */
    @Override
    public List<SysCollect> selectSysCollectList(SysCollect sysCollect)
    {
        return sysCollectMapper.selectSysCollectList(sysCollect);
    }

    /**
     * 新增酒店收藏
     * 
     * @param sysCollect 酒店收藏
     * @return 结果
     */
    @Override
    public int insertSysCollect(SysCollect sysCollect)
    {
        Long userId = SecurityUtils.getUserId();
        SysCollect find  = sysCollectMapper.selectSysCollectByUserIdAndHotelId(userId, sysCollect.getHotelId());
        if (Objects.nonNull(find)) {
            throw new GlobalException("用户已经收藏");
        }
        sysCollect.setUserId(userId);
        return sysCollectMapper.insertSysCollect(sysCollect);
    }

    /**
     * 修改酒店收藏
     * 
     * @param sysCollect 酒店收藏
     * @return 结果
     */
    @Override
    public int updateSysCollect(SysCollect sysCollect)
    {
        return sysCollectMapper.updateSysCollect(sysCollect);
    }

    /**
     * 批量删除酒店收藏
     * 
     * @param userIds 需要删除的酒店收藏主键
     * @return 结果
     */
    @Override
    public int deleteSysCollectByUserIds(Long[] userIds)
    {
        return sysCollectMapper.deleteSysCollectByUserIds(userIds);
    }

    /**
     * 删除酒店收藏信息
     * 
     * @param userId 酒店收藏主键
     * @return 结果
     */
    @Override
    public int deleteSysCollectByUserId(Long userId)
    {
        return sysCollectMapper.deleteSysCollectByUserId(userId);
    }

    @Override
    public List<SysCollectResp> selectSysCollectRespList(SysCollect sysCollect) {
        return sysCollectMapper.selectSysCollectRespList(sysCollect);
    }

    @Override
    public List<SysCollectResp> selectSysCollectRespFrontList(SysCollect sysCollect) {
        sysCollect.setUserId(SecurityUtils.getUserId());
        return sysCollectMapper.selectSysCollectRespList(sysCollect);
    }

    @Override
    public int deleteSysCollectByHotelId(Long hotelId) {
        return sysCollectMapper.deleteSysCollectByHotelIdAndUserId(SecurityUtils.getUserId(), hotelId);
    }
}
